


--经验条
class.exp_button = extends(class.button)
{
    reload = true,
    new = function (parent,icon,x,y,w,h)
        local panel = class.exp_button:builder 
        {
            parent = parent,
            x = x,
            y = y,
            w = w,
            h = h,
            normal_image = icon,
        }
        return panel
    end,

    init = function (self)
        class.button.init(self)
        self.frame1 = self:add_frame('tooltip_backdrop1')
        self.frame2 = self.frame1:add_panel('',5,4,self.w-10,self.h-10)
        self.frame2:add_panel([[ui\expbar.tga]])
        self.frame2.max_w = self.frame2.w
        self.frame2:set_view_port(true)
        self.exp_name = self:add_text('',0,0,nil,nil,9,5)
        --模型特效，用面板做底层防止特殊情况无法移动特效
        self.model = self:add_panel('',self.w*0.39,self.h*0.65)
        self.model:add_model([[ui_eff_golden_surround_square_hero_levelup.mdx]])
        self.model:hide()
        
        return self
    end,

    update = function(self,unit)
        local min = unit.exp_need[unit.level] or 0
        local max = unit.exp_need[unit.level+1]
        if unit:get_data('转生次数',0)>0 then
            self.model:show()
        else
            self.model:hide()
        end
        if max then
            local xp1 = unit.exp - min
            local xp2 = max - min
            local rate = xp1/xp2
            self.show_text = ('%0.f/%0.f'):format(xp1,xp2)
            self.frame2:set_width(self.frame2.max_w * rate + 0.01)
            self.exp_name:set_text(('等级%s %s'):format(unit.level,unit.title or unit.name))
        else
            self.frame2:set_width(self.frame2.max_w)
            self.exp_name:set_text(('等级%s[满级] %s'):format(unit.level,unit.title or unit.name))
        end

    end,
    on_button_mouse_enter = function(self)
        self:tooltip(self.show_text,'','topright',200)
        
    end,
    on_button_clicked = function(self)
        ac.sync('同步-点击经验条')
    end,
}